package 查找;

public class search {
    public static void main(String[] args) {
        int arr[] = {1,8,10,100,123};
        int result = binarySearch(arr,0,arr.length -1,123);
        System.out.println(result);
    }
    public static int binarySearch (int[] arr,int left,int right,int findVal){
        int mid = (left+right)/2;
        int midVal = arr[mid];
        if (findVal>midVal){
            return binarySearch(arr, mid+1, right, findVal);

        }else if(findVal<midVal){
            return binarySearch(arr, left, mid-1, findVal);
        }else{
            return mid;
        }

    }
}
